{if !empty($data)}
    {!$data}
{* json encode everything? *}
{elseif !empty($directory)}
    [
    {foreach $directory as $file}
        {
            "owner": {!= json_encode($file->fileInfo->ownerName)},
            "hidden": {!= json_encode($file->fileInfo->hidden)},
            "protected": {!= json_encode($file->fileInfo->protected)},
            "size": {!= json_encode($file->size)},
            "mimeType": {!= json_encode($file->mimetypeText)},
            "url": {!= json_encode($file->url)},
            "name": {!= json_encode($file->name)}
        }
        {if !$iterator->isLast()},{/if}
    {/foreach}
    ]
{elseif !empty($file)}
        {
            "owner": {!= json_encode($file->fileInfo->ownerName)},
            "hidden": {!= json_encode($file->fileInfo->hidden)},
            "protected": {!= json_encode($file->fileInfo->protected)},
            "size": {!= json_encode($file->size)},
            "mimeType": {!= json_encode($file->mimetypeText)},
            "url": {!= json_encode($file->url)},
            "name": {!= json_encode($file->name)}
        }
{/if}

